// import { reactive } from 'vue';
import { reactive } from 'vue';
import { apiService } from '../../api/apiService';
// import { getMaintainexamOrderDetail, postMaintainchecktransfer } from '../../api/server';
import { getMaintainexamOrderDetail, postMaintainchecklog, maintainworkorderFinish, maintainworkorderAccepting, postMaintainchecktransfer } from '../../api/server';
import { useRoute } from 'vue-router';
import { showSuccess } from '../../util/MessageDeal';

// import { ssm } from '../../util/ServerLang';

export default function MaintaincheckorderDetailSetup () {
    const route = useRoute();

    const maintaincheckorder = reactive({
        orderid: '',
        detail: {}
    });

    const setOrderId = () => {
        const { maintainworkorderid } = route.query;
        maintaincheckorder.orderid = maintainworkorderid;
    };

    const queryMaintaincheckorderDetail = (callback) => {
        apiService({
            api: getMaintainexamOrderDetail,
            param: {
                maintainworkorderid: maintaincheckorder.orderid
            },
            success: (data) => {
                maintaincheckorder.detail = data.value;
                callback && callback();
            }
        });
    };
    const getMaintaincheckorderDetail = (param) => {
        return new Promise((resolve, reject) => {
            apiService({
                api: getMaintainexamOrderDetail,
                param: {
                    ...param

                },
                success: (data) => {
                    resolve(data);
                },
                error: (err) => {
                    reject(err);
                }
            });
        });
    };

    const getMaintainchecklog = () => {
        return new Promise((resolve, reject) => {
            apiService({
                api: postMaintainchecklog,
                param: {
                    maintainworkorderid: maintaincheckorder.orderid
                },
                success: (data) => {
                    resolve(data);
                },
                error: (err) => {
                    reject(err);
                }
            });
        });
    };

    const postMaintainworkorderFinish = () => {
        return new Promise((resolve, reject) => {
            apiService({
                api: maintainworkorderFinish,
                param: {
                    maintainworkorderid: maintaincheckorder.orderid
                },
                success: (data) => {
                    resolve(data);
                },
                error: (err) => {
                    reject(err);
                }
            });
        });
    };

    const postMaintainworkorderAccepting = () => {
        return new Promise((resolve, reject) => {
            apiService({
                api: maintainworkorderAccepting,
                param: {
                    maintainworkorderid: maintaincheckorder.orderid
                },
                success: (data) => {
                    resolve(data);
                },
                error: (err) => {
                    reject(err);
                }
            });
        });
    };
    const postmaintaincheckTransfer = (param, callback) => {
        apiService({
            api: postMaintainchecktransfer,
            param: { ...param },
            success: () => {
                showSuccess('转派成功');
                callback && callback();
            }
        });
    };

    return {
        setOrderId,
        queryMaintaincheckorderDetail,
        maintaincheckorder,
        getMaintaincheckorderDetail,
        postmaintaincheckTransfer,
        getMaintainchecklog,
        postMaintainworkorderFinish,
        postMaintainworkorderAccepting
    };
}
